package com.augurit.wf.common.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.augurit.common.base.dao.BaseDao;
import com.augurit.wf.common.entity.WfBusInstance;

@Repository
public class WfBusInstanceDao extends BaseDao<WfBusInstance, Long> {
	
	public WfBusInstance getByprocessInstanceId(String processInstanceId){
		String hql = "from WfBusInstance ps where ps.procInstId = ?";
		return this.findUnique(hql, processInstanceId);
	}
	
	/**
	 * 根据模板code删除
	 * @param templateCode
	 */
	public void deleteByTemplateId(Long templateId){
		if(templateId != null){
			List<WfBusInstance> entities = this.findBy("templateId", templateId);
			if(entities != null && entities.size() > 0){
				this.delete(entities);
			}
		}
	}
	
	/**
	 * 根据流程实例id删除
	 * @param templateCode
	 */
	public void deleteByProcInstId(String procInstId){
		if(procInstId != null && procInstId.trim().length()>0){
			String hql = "from WfBusInstance ps where ps.procInstId='"+procInstId +"'";
			WfBusInstance entity = this.findUnique(hql);
			if(entity != null){
				this.delete(entity);
			}
		}
	}
}